home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Mail / MailEnclosure / Source.v0.15 / EnhancedText.m < prev    next >
Text File  |  1995-06-12  |  2KB  |  94 lines

  1. /*
  2.  
  3.   Ronin Consulting, Inc.
  4.     Copyright (C) 1992, Nicholas Christopher (nwc@gun.com)
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.  
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU Library General Public
  17.     License along with this library; if not, write to the Free
  18.     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. */
  21. #import "EnhancedText.h"
  22. #import <appkit/nextstd.h>
  23. #import <string.h>
  24.  
  25. static char *returnBuffer = (char *)0;
  26.  
  27. @implementation Text (EnhancedText)
  28.  
  29. - appendString: (const char *) str
  30. {
  31.    int len;
  32.  
  33.    len = [self textLength];
  34.    [self setSel: len : len];
  35.    [self replaceSel: str];
  36.    [self scrollSelToVisible];
  37.    
  38.    return self;
  39. }
  40.  
  41. - empty: sender
  42. {
  43.    BOOL editable, selectable;
  44.  
  45. //   [self setSel: 0 : [self textLength] + 1 ];             /* select the entire text */
  46.    [self selectAll: sender];
  47.  
  48.    /*
  49.     * To delete the text must be editable so copy aside the current
  50.     * editable and selectable settings, set the text editable, delete
  51.     * and then restore the copied aside values.
  52.     */
  53.    editable = [self isEditable];
  54.    selectable = [self isSelectable];
  55.  
  56.    [self setEditable: YES];
  57.    [self delete: sender];
  58.  
  59.    [self setEditable: editable];
  60.    [self setSelectable: selectable];
  61.  
  62.    return self;
  63. }
  64.  
  65. - (const char *) selectedText
  66. {
  67.    NXSelPt start, end;
  68.    int numChars;
  69.  
  70.    [self getSel: &start : &end];
  71.    numChars = end.cp - start.cp;
  72.  
  73.    if(returnBuffer)
  74.    {
  75.       NX_FREE(returnBuffer);
  76.       returnBuffer = (char *)0;
  77.    }
  78.    
  79.    NX_MALLOC(returnBuffer, char, numChars + 1);
  80.  
  81.    [self getSubstring: returnBuffer start: start.cp length: numChars];
  82.    returnBuffer[numChars] = (char)0;
  83.    
  84.    return (const char *)returnBuffer;
  85. }
  86.  
  87. - (const char *) stringValue
  88. {
  89.    [self selectAll: self];
  90.    return [self selectedText];
  91. }
  92.  
  93. @end
  94.